package com.wsh.controller.${package};

import com.wsh.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;

import com.wsh.${package}.${className}Service;
import com.wsh.dto.${package}.${className}Dto;


/**
* @author ${author}
* @date ${date}
*/
@Slf4j
@Api(tags = "${apiAlias}管理")
@RestController
@RequestMapping("/${package}/${changeClassName}")
public class ${className}Controller {

    @Autowired
    private ${className}Service ${changeClassName}Service;

    @GetMapping("/list")
    @PreAuthorize("@el.check('${changeClassName}:list')")
    @ApiOperation(value = "${apiAlias}列表")
    public Object list(${className}Dto ${changeClassName}Dto) {
        log.info("${className}Controlle ==> list params={}", ${changeClassName}Dto);
        return JsonResult.success(${changeClassName}Service.getList(${changeClassName}Dto));
    }

    @GetMapping("/getById")
    @PreAuthorize("@el.check('${changeClassName}:getById')")
    @ApiOperation(value = "查询${apiAlias}")
    public Object getById(@RequestParam String formId) {
        log.info("${className}Controlle ==> getById formId={}", formId);
        return JsonResult.success(${changeClassName}Service.queryVo(formId));
    }

    @PostMapping("/save")
    @PreAuthorize("@el.check('${changeClassName}:save')")
    @ApiOperation(value = "保存${apiAlias}")
    public Object save(@Valid @RequestBody ${className}Dto ${changeClassName}Dto) {
        log.info("${className}Controlle ==> save params={}", ${changeClassName}Dto);
        return JsonResult.success(${changeClassName}Service.save${className}(${changeClassName}Dto));
    }

    @PostMapping("/del")
    @PreAuthorize("@el.check('${changeClassName}:del')")
    @ApiOperation(value = "删除${apiAlias}")
    public Object del(@RequestParam String formId) {
        log.info("${className}Controlle ==> del formId={}", formId);
        return JsonResult.success(${changeClassName}Service.removeById(formId));
    }

}
